/*****************************************************************
Wowengine - v0.1

File: wen_input.cpp
Creation date: 2009-08-05
*****************************************************************/

/****************************************************************/
#include "wen_input.h"
//----------------------------------------------------------------
using namespace wen;
/****************************************************************/

Input::Input()
{
	Reset();

	// Tomamos la posicion actual del mouse, esto se esta haciendo mediante winapi, lo logico seria mudarlo a DirectInput

	POINT CursorPos;
	GetCursorPos(&CursorPos);

	m_alMouseScreenAbsPos[0] = CursorPos.x;
	m_alMouseScreenAbsPos[1] = CursorPos.y;
	m_alMouseScreenAbsPos[2] = 0;
}
//------------------------------------------------------------------------------
Input::~Input()
{
}
//------------------------------------------------------------------------------
void Input::UpdateMouse()
{
	// Update the mouse buttons data based on the previous acquire data
	for (int b = 0; b < 3; b++)
	{
		if (m_aucMouseBut[b])
		{
			if (!m_abButState[b])
			{
				m_abMouseButClick[b] = true;
				m_abButState[b] = true;
			}
			else
			{
				m_abMouseButClick[b] = false;
			}
		}
		else
		{
			if (m_abButState[b])
			{
				m_abButState[b] = false;
			}
		}
	}
}
//------------------------------------------------------------------------------
void Input::UpdateKeyboard()
{
	//Update the key events data based on the previous acquire data
	for(int k = 0; k < 256; k++)
	{
		if (m_aucKeyBuffer[k] != m_aucKeyPrevBuffer[k])
		{
			if (GetKeyDown(k))
			{
				m_aucKeyEvent[k] = KS_DOWN;
			}
			else
			{
				m_aucKeyEvent[k] = KS_UP;
			}
		}
		else
		{
			m_aucKeyEvent[k] = KS_NONE;
		}
	}
}
//------------------------------------------------------------------------------
void Input::SetMousePos(long lPosX, long lPosY, long lPosZ)
{
	m_alMouseRelPos[POS_X] = lPosX - m_alMouseScreenAbsPos[POS_X];
	m_alMouseRelPos[POS_Y] = lPosY - m_alMouseScreenAbsPos[POS_Y];
	m_alMouseRelPos[POS_Z] = lPosZ - m_alMouseScreenAbsPos[POS_Z];

	m_alMouseScreenAbsPos[POS_X] = lPosX;
	m_alMouseScreenAbsPos[POS_Y] = lPosY;
	m_alMouseScreenAbsPos[POS_Z] = lPosZ;
}
//------------------------------------------------------------------------------
void Input::EventClean()
{
	ZeroMemory(&m_aucKeyEvent, sizeof(m_aucKeyEvent));
}
//------------------------------------------------------------------------------
void Input::Reset()
{
	ZeroMemory(&m_aucKeyBuffer, sizeof(m_aucKeyBuffer));
	ZeroMemory(&m_aucKeyPrevBuffer, sizeof(m_aucKeyPrevBuffer));
	ZeroMemory(&m_aucKeyEvent, sizeof(m_aucKeyEvent));

	for (int eje = 0; eje < 3; eje++)
	{
		m_alMouseScreenAbsPos[eje] = 0;
		m_alMouseRelPos[eje] = 0;
		m_aucMouseBut[eje] = 0;
		m_abMouseButClick[eje] = false;
		m_abButState[eje] = false;
	}
}
//------------------------------------------------------------------------------
